Passed
Push — master ( 0a8095...60f354 )
by hung
01:03
created

output.js ➔ ???   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 5
dl 0
loc 25
rs 8.439
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A output.js ➔ ... ➔ ??? 0 8 2
1
const fs = require('fs')
2
const { join } = require('path')
3
const { Writable } = require('stream')
4
5
module.exports = (output, data) => {
6
  if (!data) {
7
    return null
8
  }
9
  if (!output) {
10
    console.log(data)
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
11
  } else if (typeof output === 'string') {
12
    const path = join(__dirname, '../', output)
13
    fs.open(path, fs.W_OK, err => {
14
      if (err) {
15
        console.error(`Cannot write file to ${path}`)
16
        return
17
      }
18
      // TODO: maybe use appendFile for readStream
19
      fs.writeFileSync(path, data)
20
    })
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
21
  } else if (output instanceof Writable) {
22
    output.write(data + '\r\n')
23
    output.on('error', err => {
24
      console.error(err)
25
    })
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
  } else {
27
    console.error('Invalid Output')
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
28
  }
29
}
30